package uriel.frankel.test;

import java.io.IOException;
import java.util.Locale;

import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateUtils;

public class MockedHttpClient implements HttpClient, Parcelable {

	
	
	private int mStatusIntCode = 0; 
	private int mDelay = 0;
	
	public void setDelay(int mDelay) {
		this.mDelay = mDelay;
	}

	public void setStatusIntCode(int mStatusIntCode) {
		this.mStatusIntCode = mStatusIntCode;
	}

	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		 dest.writeInt(mStatusIntCode);
		 dest.writeInt(mDelay);
	}
	
	
	public MockedHttpClient() {
		mStatusIntCode = 0;
		mDelay = 0;
	}
	
	public MockedHttpClient(Parcel in) {
		mStatusIntCode = in.readInt();
		mDelay = in.readInt();
	}

	  public static final Parcelable.Creator<MockedHttpClient> CREATOR
      = new Parcelable.Creator<MockedHttpClient>() {
  public MockedHttpClient createFromParcel(Parcel in) {
      return new MockedHttpClient(in);
  }

  public MockedHttpClient[] newArray(int size) {
      return new MockedHttpClient[size];
  }
};
	
	
	@Override
	public HttpResponse execute(HttpUriRequest request) throws IOException,
			ClientProtocolException {
		// TODO Auto-generated method stub
		return new HttpResponse() {
			
			@Override
			public void setParams(HttpParams params) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setHeaders(Header[] headers) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setHeader(String name, String value) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setHeader(Header header) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void removeHeaders(String name) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void removeHeader(Header header) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public HeaderIterator headerIterator(String name) {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public HeaderIterator headerIterator() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public ProtocolVersion getProtocolVersion() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public HttpParams getParams() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public Header getLastHeader(String name) {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public Header[] getHeaders(String arg0) {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public Header getFirstHeader(String arg0) {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public Header[] getAllHeaders() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public boolean containsHeader(String arg0) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void addHeader(String arg0, String arg1) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void addHeader(Header arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setStatusLine(ProtocolVersion ver, int code, String reason) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setStatusLine(ProtocolVersion ver, int code) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setStatusLine(StatusLine statusline) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setStatusCode(int code) throws IllegalStateException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setReasonPhrase(String reason) throws IllegalStateException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setLocale(Locale loc) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void setEntity(HttpEntity entity) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public StatusLine getStatusLine() {
				// TODO Auto-generated method stub
				return new StatusLine() {
					
					@Override
					public int getStatusCode() {
						if(MockedHttpClient.this.mDelay==0){
							return MockedHttpClient.this.mStatusIntCode;
						}else{
							try {
								Thread.sleep(MockedHttpClient.this.mDelay*DateUtils.SECOND_IN_MILLIS);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
							return MockedHttpClient.this.mStatusIntCode;
						}
					}
					
					@Override
					public String getReasonPhrase() {
						// TODO Auto-generated method stub
						return null;
					}
					
					@Override
					public ProtocolVersion getProtocolVersion() {
						// TODO Auto-generated method stub
						return null;
					}
				};
			}
			
			@Override
			public Locale getLocale() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public HttpEntity getEntity() {
				// TODO Auto-generated method stub
				return null;
			}
		};
	}

	@Override
	public HttpResponse execute(HttpUriRequest request, HttpContext context)
			throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HttpResponse execute(HttpHost target, HttpRequest request)
			throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1)
			throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HttpResponse execute(HttpHost target, HttpRequest request,
			HttpContext context) throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T execute(HttpUriRequest arg0,
			ResponseHandler<? extends T> arg1, HttpContext arg2)
			throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T execute(HttpHost arg0, HttpRequest arg1,
			ResponseHandler<? extends T> arg2) throws IOException,
			ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T execute(HttpHost arg0, HttpRequest arg1,
			ResponseHandler<? extends T> arg2, HttpContext arg3)
			throws IOException, ClientProtocolException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ClientConnectionManager getConnectionManager() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HttpParams getParams() {
		// TODO Auto-generated method stub
		return null;
	}

}
